package xcmg.device.web.account;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.infra.BasicController;
import xcmg.device.service.account.ArapService;
import xcmg.device.service.vo.account.ArapDetailVO;
import xcmg.device.service.vo.account.ArapVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

import java.util.Arrays;

@RestController
@RequestMapping("/arap")
public class ArapController extends BasicController {

    @Autowired
    private ArapService arapService;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult list(@RequestBody SearchCommonVO<ArapVO> condition)throws Exception{
        ArapVO arapVO = condition.getFilters();
        if(arapVO == null){
            arapVO = new ArapVO();
        }
        arapVO.setOrgId(getOrgId());
        condition.setFilters(arapVO);
        PageCommonVO pageCommonVO = arapService.list(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @RequestMapping(value = "/detailList",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult detailList(@RequestBody SearchCommonVO<ArapDetailVO> condition)throws Exception{
        ArapDetailVO arapVO = condition.getFilters();
        if(arapVO.getType() == 0){
            arapVO.setSupplierOrgId(getOrgId());
            arapVO.setPurchaseOrgId(arapVO.getOrgId());
        }else{
            arapVO.setPurchaseOrgId(getOrgId());
            arapVO.setSupplierOrgId(arapVO.getOrgId());
        }
        condition.setFilters(arapVO);
        PageCommonVO pageCommonVO = arapService.detailList(condition,getOrgId());
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @RequestMapping(value = "/export",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public void export( String[] ids)throws Exception {
        arapService.export(Arrays.asList(ids));
    }

    @RequestMapping(value = "/exportAll",method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public void exportAll(ArapVO condition)throws Exception {
        condition.setOrgId(getOrgId());
        arapService.exportAll(condition);
    }

    @GetMapping(value = "/getPrepPayPrice")
    @FastMappingInfo(needLogin = true)
    public ActionResult getPrepPayPrice(@RequestParam("salesBillNo") String salesBillNo)throws Exception {
       return actionValueResult(arapService.getPrepPayPrice(salesBillNo,getOrgId())) ;
    }

}
